import { Module } from 'vuex';

const userModule = {
  namespaced: true,
  state: () => ({
    userInfo: {
      token: '',
      id: '',
      name: '',
      avatar: '',
      roles: [],
      permissions: []
    }
  }),
  mutations: {
    SET_USER(state, payload) {
      state.userInfo = { ...payload };
    },
    CLEAR_USER(state) {
      state.userInfo = {
        token: '',
        id: '',
        name: '',
        avatar: '',
        roles: [],
        permissions: []
      };
    }
  },
  actions: {
    setUserInfo({ commit }, payload) {
      commit('SET_USER', payload);
    },
    clearUser({ commit }) {
      commit('CLEAR_USER');
    }
  },
  getters: {
    getUserInfo: state => state.userInfo
  }
};

export default userModule;

